package com.ibook.service.impl;

import com.ibook.common.ServerResponse;
import com.ibook.dao.ManagerMapper;
import com.ibook.pojo.Manager;
import com.ibook.service.ManagerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by heziqi on 2017/6/9.
 */
@Service
public class ManagerServiceImpl implements ManagerService{

    @Autowired
    private ManagerMapper managerMapper;

    public ServerResponse<Manager> login(String managerName, String password){
        Manager manager = managerMapper.selectByNameAndPassword(managerName,password);
        if(manager == null){
            return ServerResponse.createByErrorMessage("管理员名称或者密码错误");
        }
        managerMapper.updateLastLogin();
        manager.setManagerPassword(StringUtils.EMPTY);
        return ServerResponse.createBySuccess("登陆成功",manager);
    }
}
